package com.elysium.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import com.elysium.pojo.domain.DriverAuthMaterial;
import com.elysium.pojo.dto.DriverSummaryDto;
import com.elysium.pojo.dto.LocationChangeDto;
import com.elysium.result.R;
import com.elysium.service.IDriverAuthMaterialService;
import com.elysium.service.IDriverService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

// swagger注解：解释说明当前类的
@Tag(name = "小程序司机对象",description = "小程序司机对象")
@RestController
@RequestMapping("/app/driver")
public class AppDriverController{

    @Autowired
    public IDriverService driverService;

    @Autowired
    private IDriverAuthMaterialService driverAuthMaterialService;

    /**
     * 监听司机的位置，保存经纬度到GEO
     * @return
     */
    @Operation( summary= "司机上线处理",description = "司机上线处理接口")
    @PostMapping("/locationToGeo")
    public R<Void> locationToGeo(@RequestBody @Valid LocationChangeDto locationChangeDto){
        driverService.changLocationToGeo(locationChangeDto);
        return R.success();
    }

    /**
     * 司机上线处理
     * @return
     */
    @Operation( summary= "司机上线处理",description = "司机上线处理接口")
    @GetMapping(value = "/onLine")
    public R<DriverSummaryDto> onLine() {
        driverService.onLine();
        return R.success();
    }

    /**
     * 司机下线处理
     * @return
     */
    @Operation( summary= "司机上线处理",description = "司机上线处理接口")
    @GetMapping(value = "/offLine")
    public R<DriverSummaryDto> offLine() {
        driverService.offLine();
        return R.success();
    }

    /**
     * 获取司机今日接单数据
     * @return
     */
    @Operation( summary= "获取司机今日接单数据",description = "获取司机今日接单数据接口")
    @GetMapping(value = "/getDriverSummary")
    public R<DriverSummaryDto> getDriverSummary() {
        return R.success(driverService.getDriverSummary());
    }

    /**
     * 获取司机实名认证数据
     * @return
     */
    @Operation( summary= "获取司机实名认证数据",description = "获取司机实名认证数据接口")
    @GetMapping(value = "/realAuthInfo")
    public R<DriverAuthMaterial> realAuthInfo() {
        return R.success(driverService.getrealAuthInfo());
    }

    /**
     * 小程序司机注册
     * @param openIdCode 获取openId所需要的code
     * @return
     */
    @Operation( summary= "小程序司机注册",description = "小程序司机注册接口")
    @Parameter(name = "openIdCode",description = "获取openId的code",required = true)
    @GetMapping(value = "/register/{openIdCode}")
    @SaIgnore
    public R<Void> register(@PathVariable("openIdCode") String openIdCode) {
        driverService.register(openIdCode);
        return R.success();
    }
//    @Operation( summary= "小程序司机注册",description = "小程序司机注册接口")
//    @Parameter(name = "openIdCode",description = "获取openId的code",required = true)
//    @GetMapping(value = "/register/{openIdCode}/{phoneCode}")
//    public R<Void> register(@PathVariable("openIdCode") String openIdCode, @PathVariable("phoneCode") String phoneCode){
//        driverService.register(openIdCode, phoneCode);
//        return R.success();
//    }

    @Operation( summary= "小程序司机实名认证",description = "小程序司机实名认证接口")
    // swagger，描述参数
    @Parameter(name = "authMaterial",description = "保存的对象",required = true)
    @PostMapping("/saveRealAuth")
    public R<Void> saveRealAuth(@RequestBody @Valid DriverAuthMaterial authMaterial){
        driverAuthMaterialService.saveRealAuth(authMaterial);
        return R.success();
    }



}
